const app = new Vue({
	
	el : "#app",
	data : {
		items : [
				 {id:1001,name:"华为mate40",price:6800,count:1},
				 {id:1002,name:"苹果P12",price:7000,count:1},
				 {id:1003,name:"金立8848",price:12000,count:1},
		],
		
	},
	methods:{
		
		decrement(index){
			this.items[index].count--;
		},
		increment(index){
			this.items[index].count++;
		},
		removeTr(index){
			this.items.splice(index,1);
		}
		
	},
	computed: {
		
		totalPrice(){
			let totalPrice = 0;
			for(let item of this.items){
				totalPrice += item.price * item.count;
			}
			return totalPrice;
		}
		
	},
	filters: {
		//通过过滤器的方式实现数据转化
		getPrice(price){
			//toFixed只能处理数值类型
			return "￥" + price.toFixed(2);
		}
	}
}) 